package com.csdn.leon.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLHelper extends SQLiteOpenHelper {
	public static final String DB_NAME = "database.db";// ��ݿ����
	public static final int VERSION = 1;
	
	public static final String TABLE_CHANNEL = "channel";//��ݱ� 
	public static final String USER_TABLE="person";
	public static final String BLOG_TABLE ="blog";
	public static final String ID = "id";//
	public static final String NAME = "name";
	public static final String ORDERID = "orderId";
	public static final String SELECTED = "selected";
	public static final String BLOGTYPE = "blogtype";
	public static final String COLORID = "colorId";
	
	public static final String UERANAME = "username";
	public static final String TITLE = "title";
	private Context context;
	public SQLHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
		this.context = context;
	}

	public Context getContext(){
		return context;
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		String sql = "create table if not exists "+TABLE_CHANNEL +
				"(_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
				ID + " INTEGER , " +
				NAME + " TEXT , " +
				ORDERID + " INTEGER , " +
				SELECTED + " SELECTED ," +
				BLOGTYPE + " BLOGTYPE ," +
				COLORID +" COLORID)";
		  String sqlPerson="CREATE TABLE [person]([_ID] INTEGER PRIMARY KEY,[username] TEXT,[userface] TEXT,[rank] TEXT," +
					"[statistics] TEXT)";
		  
		  String sqlblogitem="CREATE TABLE [blog]([_ID] INTEGER PRIMARY KEY,[title] TEXT,[content] TEXT,"
					+ "[date] TEXT,[img] TEXT,[link] TEXT,[username] TEXT,[id] TEXT,[blogType] INTEGER,[totalread] TEXT," 
					+"[totalcomment] TEXT)";
		db.execSQL(sql);
		db.execSQL(sqlPerson);
		db.execSQL(sqlblogitem);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		onCreate(db);
	}

}
